package com.mvp.shq.washer.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.mvp.shq.washer.R;
import com.mvp.shq.washer.entity.Bill;
import com.mvp.shq.washer.utils.DateUtils;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/8/24.
 */

public class BillAdapter extends RecyclerView.Adapter<BillAdapter.MyViewHolder> {


    private Context context;
    private List<Bill> bills;

    public BillAdapter(Context mContext, List<Bill> list) {
        context = mContext;
        bills = list;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_expenditure, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        Bill bill = bills.get(position);
        holder.tvMachineNo.setText("NO."+bill.getOrderNo());
        holder.tvRechargeType.setText(bill.getContent());
        holder.tvTime.setText(bill.getCreateDate());
        String money = "";
        if ("0".equals(bill.getSignFlag())){
            money += "+ ";
        }else if ("1".equals(bill.getSignFlag())){
            money += "- ";
        }
        money += bill.getMoney();
        holder.tvMoney.setText(money);
    }

    @Override
    public int getItemCount() {
        return bills.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_recharge_type)
        TextView tvRechargeType;
        @BindView(R.id.tv_machine_no)
        TextView tvMachineNo;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.tv_money)
        TextView tvMoney;
        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
            AutoUtils.autoSize(itemView);
        }
    }
}
